<template>
  <view>
    <uni-popup ref="popup" background-color="#fff">
      <view class="popup">
        <view class="list-input">
          <form>
            <view class="item">
              <view class="acea-row row-middle">
                <uni-section title="" style="width: 100%">
                  <uni-data-select
                    v-model="addBlack.bankName"
                    :localdata="blackNameList"
                  ></uni-data-select>
                </uni-section>
              </view>
            </view>
            <view class="item">
              <view class="acea-row row-middle">
                <input
                  type="number"
                  class="texts"
                  placeholder="输入银行卡号"
                  v-model="addBlack.bankCode"
                  required
                />
              </view>
            </view>
			<view class="item">
			  <view class="acea-row row-middle">
			    <input
			      type="text"
			      class="texts"
			      placeholder="请输入开户支行"
			      v-model="addBlack.bankAddress"
			      required
			    />
			  </view>
			</view>
			
          </form>
        </view>
        <button class="btn" @click="submit">确定</button>
      </view>
    </uni-popup>
  </view>
</template>

<script>
import { mapGetters } from "vuex";
import { addBank } from "@/api/user.js";
export default {
  props: {
    blackNameList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      addBlack: {},
    };
  },

  computed: mapGetters(["userInfo", "isLogin"]),
  methods: {
    open() {
      this.$refs.popup.open("bottom");
    },
    submit() {
      if (!this.addBlack.bankName)
        return this.$util.Tips({
          title: "请选择银行卡",
        });
      if (!this.addBlack.bankCode)
        return this.$util.Tips({
          title: "请输入卡号",
        });
		if (!this.addBlack.bankAddress)
		  return this.$util.Tips({
		    title: "请输入开户行",
		  });
		
      const params = Object.assign(this.addBlack, {
        realName: this.userInfo.realName,
      });
      uni.showLoading({
        title: "请稍等",
      });
      addBank({
        ...params,
      })
        .then((res) => {
          this.$refs.popup.close();
          uni.showToast({
            title: res.message,
            icon: "success",
          });
          this.$emit('loadData')
          this.addBlack = {};
          
        })
        .catch((res) => {
          this.$util.Tips({
            title: res,
          });
          uni.hideLoading();
        });
    },
  },
};
</script>

<style lang="scss" scoped>
@import url("../../../static/css/gstyle.scss");
.popup {
  padding: 20rpx;

  .list-input {
    .item {
      border-bottom: 1px solid #f0f0f0;
      background: #fff;

      .row-middle {
        position: relative;
        padding: 0 25rpx;
        margin-top: 20rpx;

        .texts {
          flex: 1;
          font-size: 28rpx;
          height: 89rpx;
          line-height: 80rpx;
          display: flex;
          justify-content: center;
          align-items: center;
        }

        input {
          flex: 1;
          font-size: 28rpx;
          height: 80rpx;
          line-height: 80rpx;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }
  }
}

.uni-select__input-placeholder[data-v-6b64008e] {
    color: #6a6a6a;
    font-size: 16px;
}
</style>
